package com.mef.smsplat.service;

import java.util.Date;
import java.util.List;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mef.smsplat.dao.AdminInfoDao;
import com.mef.smsplat.dao.RoleInfoDao;
import com.mef.smsplat.dao.SmsOpraInfoDao;
import com.mef.smsplat.dao.TempVarInfoDao;
import com.mef.smsplat.dao.base.DataGridModel;
import com.mef.smsplat.dao.base.EntityDao;
import com.mef.smsplat.dao.base.Page;
import com.mef.smsplat.domain.AdminInfoDomain;
import com.mef.smsplat.domain.RoleInfoDomain;
import com.mef.smsplat.domain.SmsHistoryInfoDomain;
import com.mef.smsplat.domain.SmsOpraInfoDomain;
import com.mef.smsplat.domain.TempVarInfoDomain;
import com.mef.smsplat.service.base.BaseService;

@Service
@Transactional
public class TempVarInfoService extends BaseService<TempVarInfoDomain, String> {
	
	private TempVarInfoDao tempVarInfoDao;
	private CacheManager cacheManager;
	

	public void setTempVarInfoDao(TempVarInfoDao tempVarInfoDao) {
		this.tempVarInfoDao = tempVarInfoDao;
	}

	public void setCacheManager(CacheManager cacheManager) {
		this.cacheManager = cacheManager;
	}


	@Override
	public EntityDao getEntityDao() {
		return this.tempVarInfoDao;
	}
	
	/**
	 * 把模版变量初始化到缓存，和机场信息共用一个缓存
	 */
	public void initCache(){
		List<TempVarInfoDomain> list=this.findAll();
		Cache cache=cacheManager.getCache("staticCache");		
		for(int i=0;i<list.size();i++){
			Element e=new Element(list.get(i).getVarName(), list.get(i));
			cache.put(e);
		}
	}
	
	
}
